package download

import (
	"fmt"
	"gitee.com/swsk33/landsat-fetch/api"
	"gitee.com/swsk33/landsat-fetch/global"
	"gitee.com/swsk33/sclog"
	"github.com/spf13/cobra"
)

// 列出全部下载列表的子命令
var listCmd = &cobra.Command{
	Use:   "list",
	Short: "列出下载任务列表",
	Long:  "列出全部下载任务列表的Label名称",
	Run: func(cmd *cobra.Command, args []string) {
		// 登录
		e := api.Login(global.TotalConfig.Auth.Username, global.TotalConfig.Auth.Token)
		if e != nil {
			sclog.ErrorLine(e.Error())
			return
		}
		// 执行查询
		sclog.InfoLine("正在查询下载列表...")
		list, e := api.GetDownloadList()
		if e != nil {
			sclog.ErrorLine(e.Error())
			return
		}
		sclog.InfoLine("查询完成！结果如下：")
		for _, label := range list {
			fmt.Println(label)
		}
	},
}

func init() {
	RootDownloadCmd.AddCommand(listCmd)
}